//
//  GetUserInfoApi.m
//  SmartClothes
//
//  Created by Rex on 16/4/22.
//  Copyright © 2016年 Rex. All rights reserved.
//

#import "GetUserInfoApi.h"

@implementation GetUserInfoApi{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/user/get_user_info";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    
    NSMutableDictionary * mdict = [NSMutableDictionary getPubdic];
    NSString *sign= [NSString getSign:mdict];
    
    [mdict setObject:sign forKey:@"sign"];
    
    return mdict;
}

- (NSString *)userId {
    return [[[self responseJSONObject] objectForKey:@"userId"] stringValue];
}

- (void)analyseResponseObject {
    
    NSDictionary *dic = [self responseJSONObject];
    if([dic[@"errcode"] intValue] == 0) {
        NSDictionary * data = dic[@"data"];
        NSLog(@"[获取到用户信息data = %@]",data);
        SAVE_OBJECT(data[@"image"], IMAGE);
        SAVE_OBJECT(data[@"nickname"], NICKNAME);
        SAVE_OBJECT(data[@"username"], USERNAME);
        SAVE_OBJECT(data[@"bracelet_radiation_limit"], BraceletRadiationLimit);
        SAVE_OBJECT(data[@"bracelet_sport_target"], BraceletSportTarget);
        SAVE_OBJECT(data[@"bracelet_sleep_target"], BraceletSleepTarget);

        SAVE_OBJECT(data[@"sex"], SEX);//1  2女
        SAVE_OBJECT(data[@"birth"], BIRTH);//yyyy-mm
//        DTCSAVE_OBJECT(data[@"height"], HEIGHT);
//        DTCSAVE_OBJECT(data[@"weight"], WEIGHT);
        SAVE_OBJECT(data, INFODIC);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"UserInfoUpdate" object:nil];
        
    } else {
       
    }
    
}

-(void)dealloc
{
    NSLog(@"GetUserInfoApi dealloc");
}

@end
